import api from '../index'
import type {
	ResponseData,
	PagingData,
	pageParam,
	RequestFromType
} from '../index'
import type {OrderGroupItem} from '.'

//获取秒杀规则
export const getSeckillRule = () =>
	api.get<ResponseData<{
		ruleState: number
		ruleMsg: string
	}>>('customer/api/activity/flashSale/rule', {
		custom: {
			auth: false
		}
	})
export type SeckillGoodsItem = {
	buyStock: number
	coverImg: string
	createTime: string
	id: number
	oldPrice: number
	peopleNumber: number
	peopleState: number
	price: number
	productId: string
	productName: string
	shamStock: number
	skuId: string
	skuName: string
	stock: number
	storeId: string
	timeLimit: number
	stockSold:number
}
// 秒杀商品列表
export const getSeckillGoodsList = (data: pageParam) =>
	api.get < ResponseData < PagingData < SeckillGoodsItem >>> ('customer/api/activity/flashSale/list', {
		data,
		custom: {
			auth: false
		}
	})


export type SeckillSkuInfo = {
	flashSaleOldPrice:number//秒杀原来的价格
	flashSalePrice:number//秒杀价格
	flashSaleStock:number//秒杀剩余库存
	type?: 1|2,//1=秒杀，2=拼团
	groupStock:number//拼团库存
	groupPrice:number//拼团价
	groupOldPrice:number//拼团原来的价格
	groupListTotal:number//拼团列表总数
	groupList:Array<OrderGroupItem&{timer?:number,surplusTime?:string,overTime:string}>//拼团列表
	flashSale:{
		endTime:number
	}
}
// 查询一个SKU的活动
export const getSeckillSkuInfo = (skuId:string) =>
	api.get<ResponseData<SeckillSkuInfo>>(`customer/api/activity/sku/info/${skuId}`, {
		custom: {
			auth: false
		}
	})